﻿using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;

namespace Magicodes.Plus.Core.Configuration
{
    /// <summary>
    ///     配置管理器（单例）
    /// </summary>
    public class AppConfigurationManager : IAppConfigurationManager
    {
        /// <summary>
        ///     配置
        /// </summary>
        public IConfiguration Configuration { get; set; }

        /// <summary>
        ///     主机环境变量
        /// </summary>
        public IHostingEnvironment Environment { get; set; }

        public void Initialize()
        {
            var builder = new ConfigurationBuilder()
                .SetBasePath(Environment.ContentRootPath)
                .AddJsonFile("appsettings.json", true, true);
            Configuration = builder.Build();
        }
    }
}